'use strict';

const HttpStatus = require('http-status-codes');

module.exports = () => async (ctx, next) => {
  const loginKey = ctx.app.config.LOGIN_KEY;
  if (ctx.jwterror) ctx.throw(ctx.HttpStatus.OK, ctx.jwterror);
  if (!ctx[loginKey]) {
    ctx.throw(HttpStatus.UNAUTHORIZED, { code: -401, message: '用户未登录' });
  }
  await next();
};
